<template>
  <div class="governmentDetails-wrap">
    <div class="details-wrap">
<!--      <van-image class="img"-->
<!--                 height="30rem"-->
<!--                 width="100%"-->
<!--                 :src="`${fileUrl}/${detail?.mainImageId}`" fit="cover" />-->
      <van-swipe v-if="getImages().length" class="my-swipe" :autoplay="3000" indicator-color="white" >
        <van-swipe-item v-for="(item, index) in getImages()" :key="index">
          <van-image
              fit="cover"
              height="30rem"
              width="100%"
              class="img" :src="`${fileUrl}/${item}`" @click="()=>{handelswip(index)}" />
        </van-swipe-item>
      </van-swipe>
    </div>
    <div class="main-header">
      <div class="header-top">

        <span class="title-name">{{ detail?.name }}</span>
        <div class="address-wrap">
          <div class="unit-box" @click="onNavi">
            <van-image class="icon" :src="AddressIcon" mode="scaleToFill" />
            <div>门店地址:{{ detail?.address }}</div>
          </div>
          <a :href="'tel:' + detail?.telephone">
            <div class="iconCall">
              <img class="icon" :src="CallIcon" mode="scaleToFill" />
            </div>
          </a>
        </div>
      </div>
      <!-- <div class="date-wrap">
                <img class="icon" :src="DateIcon" mode="scaleToFill" />
                <span>周一至周日:20-80</span>
            </div> -->
      <div class="line"></div>
      <div class="detailsTitle">店铺详情</div>
      <div >
        <div v-html="detail?.detail" class="htmlDetail"></div>
      </div>
      <!-- <div @click="handlePay">支付</div> -->
    </div>
  </div>
  <van-action-sheet
      v-model:show="show"
      :actions="actions"
      @select="(e) => onSelect(e, {
        ...detail,
        scenicAreaName:detail.address,
      },true)"
      cancel-text="取消"
      close-on-click-action
  />
</template>
<script setup lang="ts">
import AddressIcon from '@/assets/address.png';
import CouponIcon from '@/assets/ic-coupons-count.png';
import CallIcon from '@/assets/call.png';
import DateIcon from '@/assets/date.png';
import api from '@/api/index';
import { onBeforeRouteLeave, useRoute, useRouter } from 'vue-router';
import { ref } from 'vue';
import {showImagePreview} from "vant";
import {useActionSheet} from "@/hooks/useNavigation.js";
import {callWxNavi, isMiniProgram} from "@/utils/wx-utils.ts";
const route = useRoute();
const fileUrl = import.meta.env.VITE_FILE_URL;

const handlePay = () => {
  // uni.navigateTo({
  //   url: '/mainPages/payment/index',
  // })
};
const detail = ref(null);
function getDetail() {
  api.getBrandDetail(null, route.query.id).then((res) => {
    if (res.code == '200') {
      detail.value = res.data;
      if (detail.value.detail) {
        detail.value.detail = detail.value.detail.replace(
          /<img/g,
          "<img style='max-width:100%;height:auto;'"
        );
      }
    }
  });
}
getDetail();

function  getImages (){
  return [
    detail.value?.mainImageId,
    ...( detail.value?.turnImageId ?detail.value.turnImageId.split(','):[])
  ];
}
function handelswip(index) {
  showImagePreview({
    images:getImages().map(item => `${fileUrl}/${item}`),
    startPosition:index
  });
}
const {show, actions, navigationClick, onSelect} = useActionSheet()

function onNavi() {
  console.log('brand detail onNavi',detail.value)

  if (isMiniProgram()) {

    callWxNavi({
      lat: Number.parseFloat(detail.value.latitude),
      log: Number.parseFloat(detail.value.longitude),
      address: detail.value.address,
      redirectUrl: location.href,
    });
  } else {
    navigationClick()
  }
}
</script>
<style scoped lang="scss">
.governmentDetails-wrap {
  overflow: scroll;
  min-height: 100vh;
  width: 100%;
  background: #fff;
  position: relative;
  .details-wrap {
    //height: 18rem;
    // background: red;
    //.img {
    //  width: 100%;
    //  height: 100%;
    //  object-fit: cover;
    //}
  }
  .main-header {
    position: absolute;
    top: 25rem;
    min-height: 10rem;
    width: 100%;
    background: #fff;
    z-index: 10;
    // background: #eee;
    border-top-right-radius: 1.8rem;
    border-top-left-radius: 1.8rem;
    .header-top {
      padding: 1rem;
      box-sizing: border-box;
    }
    .label-wrap {
      display: flex;
      justify-content: space-between;
      .label-content {
        display: flex;

        .label {
          // width: 120px;
          height: 2rem;
          border: 1px solid rgb(243, 162, 127);
          font-size: 1.2rem;
          padding-left: 1rem;
          padding-right: 1rem;
          box-sizing: border-box;
          border-radius: 1.5rem;
          display: flex;
          background: rgb(253, 237, 245);
          color: rgb(243, 162, 127);
          .reduction {
            padding-right: 0.3rem;
            box-sizing: border-box;
            border-right: 1px dotted rgb(243, 162, 127);
            margin-right: 0.3rem;
          }
        }
      }
    }
    .preferential-box {
      display: flex;
      align-items: center;
      color: #ccc;
      .icon {
        width: 1.8rem;
        height: 1.8rem;
      }
    }
    .line {
      width: 100%;
      height: 1px;
      background: #eee;
    }
    .title-name {
      margin-top: 0.5rem;
      display: inline-block;
    }
    .details-wrap {
      padding: 1rem;
      box-sizing: border-box;
      font-weight: bold;
    }
    // background: rebeccapurple;
  }
  .address-wrap {
    display: flex;
    justify-content: space-between;
    .unit-box {
      margin-top: 0.5rem;
      display: flex;
      align-items: center;
      font-size: 1.2rem;
      .icon {
        width: 1.8rem;
        height: 1.8rem;
      }
    }
    .iconCall {
      width: 2.8rem;
      height: 2.8rem;
      .icon {
        width: 100%;
        height: 100%;
      }
    }
  }
  .date-wrap {
    // margin-top: 10px;
    padding: 1rem;
    box-sizing: border-box;
    display: flex;
    align-items: center;
    font-size: 1.2rem;
    .icon {
      width: 1.8rem;
      height: 1.8rem;
    }
  }
}
.htmlDetail {
  padding-left: 10px;
  padding-right: 10px
}
.detailsTitle {
  font-weight: bold;
  padding: 1rem;
}
</style>
